package cn.school.mybatis.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.school.mybatis.dao.SubjectDao;
import cn.school.mybatis.pojo.Subject;
import cn.school.mybatis.util.MyBatisUtil;

public class MyBteaTest2 {

	public static void main(String[] args) {
		// test2();
		// grade的查询

		testAdd();
	}

	public static void testAdd() {
		SqlSession s = MyBatisUtil.get();
		SubjectDao dao = s.getMapper(SubjectDao.class);
		Subject sub = new Subject("潜艇维修", 20, 3);
		dao.add(sub);
		s.commit();// 提交
		MyBatisUtil.close(s);
		System.out.println("新课程的课程号是:" + sub.getId());
	}

	public static void test2() {
		SqlSession s = MyBatisUtil.get();
		SubjectDao dao = s.getMapper(SubjectDao.class);
		List<Subject> list = dao.search();
		MyBatisUtil.close(s);
		for (Subject sb : list) {
			System.out.println(sb);
		}
	}

	// 不推荐
	public static void test1() {
		SqlSession s = MyBatisUtil.get();
		List<Subject> list = s.selectList("cn.school.mybatis.dao.SubjectDao.search");
		MyBatisUtil.close(s);
		for (Subject sb : list) {
			System.out.println(sb);
		}
	}
}
